package com.zhixin.fans.ks.ui.module;

import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.alibaba.fastjson.JSON;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.zhixin.fans.ks.KeyConstant;
import com.zhixin.fans.ks.R;
import com.zhixin.fans.ks.api.res.IndexModule;
import com.zhixin.fans.ks.api.res.SubModule;
import com.zhixin.fans.ks.ui.base.BaseDaggerActivity;
import com.zhixin.fans.ks.ui.charge.ModuleGoodActivity;

import org.eenie.common.views.QMUIWindowInsetLinearLayout;
import org.eenie.common.views.TopBarLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class ModuleItemActivity extends BaseDaggerActivity implements BaseQuickAdapter.OnItemClickListener {
    public static final String ROUTE_PATH = "/order/order_detail";
    @BindView(R.id.top_bar)
    TopBarLayout mTopBar;
    @BindView(R.id.rv_modules)
    RecyclerView mRvModules;
    @BindView(R.id.fragment_container)
    QMUIWindowInsetLinearLayout mFragmentContainer;


    IndexModule mModuleType;


    ModuleItemAdapter mModuleItemAdapter;


    List<SubModule> mSubModules = new ArrayList<>();


    @Override
    public int initContentView() {
        return R.layout.activity_module_item;
    }

    @Override
    public void initInjector() {


        mModuleType = JSON.parseObject(getIntent().getStringExtra("module_type"), IndexModule.class);

        if (mModuleType != null) {
            mSubModules.addAll(mModuleType.getGc_listCoodCategory());
        }

    }

    @Override
    public void initUiAndListener() {
        ButterKnife.bind(this);

        mTopBar.setTitle(mModuleType.getGc_name());
        mTopBar.addLeftBackImageButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });


        mRvModules.setLayoutManager(new GridLayoutManager(mContext, 4));
        mRvModules.setAdapter(mModuleItemAdapter = new ModuleItemAdapter(mSubModules));

        mModuleItemAdapter.setOnItemClickListener(this);


    }





    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        SubModule module = (SubModule) adapter.getItem(position);

        startActivity(new Intent(mContext, ModuleGoodActivity.class).putExtra(KeyConstant.KEY_SUB_MODULE, JSON.toJSONString(module)));
    }
}
